<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="http_request.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>http_request.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'http_request.js'<BR/><BR/>
	
</p>

<hr>



<!-- ========== METHOD SUMMARY =========== -->

	<a name="method_summary"><!-- --></a>
	<table border="1" cellpadding="3" cellspacing="0" width="100%">
		<tr bgcolor="#CCCCFF" class="TableHeadingColor">
			<td colspan=2>
				<font size="+2">
					<b>Method Summary</b>
				</font>
			</td>
		</tr>
	
		
		   <tr bgcolor="white" class="TableRowColor">
		      <td align="right" valign="top" width="1%">
			 <font size="-1">
			    <code>static&nbsp;void</code>
			 </font>
		      </td>
		      <td>
			 <code>
			    <b>
			       <a href="GLOBALS.html#!s!httpRequest">httpRequest</a></b>(reqType,url,asynch,respHandle)
			 </code>
			 <br>
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 Aquesta funcio crea una peticio adaptada al tipus de navagador que s'utilitza
 Si la peticio es POST envia a executar els par`ametres adequats.
		      </td>
		   </tr>
		
		   <tr bgcolor="white" class="TableRowColor">
		      <td align="right" valign="top" width="1%">
			 <font size="-1">
			    <code>static&nbsp;void</code>
			 </font>
		      </td>
		      <td>
			 <code>
			    <b>
			       <a href="GLOBALS.html#!s!initReq">initReq</a></b>(reqType,url,bool,respHandle)
			 </code>
			 <br>
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 Aquesta funcio munta i emet una peticio GET o POST, si es POST afegeix la capalera
 i les dades del formulari de l'ultim parametre, sino van a l'URL
 utilitza la variable request creada segons el navegador per httpRequest..
		      </td>
		   </tr>
		
		   <tr bgcolor="white" class="TableRowColor">
		      <td align="right" valign="top" width="1%">
			 <font size="-1">
			    <code>static&nbsp;void</code>
			 </font>
		      </td>
		      <td>
			 <code>
			    <b>
			       <a href="GLOBALS.html#!s!setQueryString">setQueryString</a></b>(x)
			 </code>
			 <br>
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 Donat un formulari, extreu a la variable queryString tots els camps del formulari
 amb els seus valors, formatat per fer una peticio.
		      </td>
		   </tr>
		
	
	</table>
    <p>

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 *Arxiu que genera els http_requests per treballar amb Ajax
 *
 * <span class="attrib">@copyright</span> 2009 - Equip de Desenvolupament de ASI 2   
 * <span class="attrib">@link</span> http://www.iescopernic.com
 * <span class="attrib">@version</span> 1.0
 * <span class="attrib">@license</span> GNU/GPL-http://www.gnu.org/copyleft/gpl.html  
 * <span class="attrib">@package</span> CreditSintesis 
 * <span class="attrib">@subpackage</span> scrips 
 * <span class="attrib">@author</span> ASI 2
 */</span>

var request = null;  <span class="comment">// variable local per la peticio</span>
var queryString;     <span class="comment">// variable per enviar tots els camps del formulari.</span>


<span class="comment">/**
 * Aquesta funcio munta i emet una peticio GET o POST, si es POST afegeix la capalera
 * i les dades del formulari de l'ultim parametre, sino van a l'URL
 * utilitza la variable request creada segons el navegador per httpRequest..
 * Parametres :
 *  [0] - reqType    : es el tipus de peticio (GET o POST)
 *  [1] - url        : es l'adreca complerta de la peticio
 *  [2] - bool       : es si es sincrona false, o asincrona true
 *  [3] - respHandle : es la funcio destinataria de la resposta.
 *  [4] - (opcional) : Aquest parametre pot rebre per exemple  una llista de peticio
 *                     o qualsevol altre cosa que es vulgui enviar amb POST
 *  Emet un missatge d'error si no es pot dur a terme la peticio
 */</span>
<span class="reserved">function</span> initReq(reqType,url,bool,respHandle){
    try{
        request.onreadystatechange=respHandle;
        request.open(reqType,url,bool);
        <span class="reserved">if</span>(reqType.toLowerCase() == <span class="literal">"post"</span>) {
            request.setRequestHeader(<span class="literal">"Content-Type"</span>,<span class="literal">"application/x-www-form-urlencoded; charset=UTF-8"</span>);
            request.send(arguments[4]);
        } <span class="reserved">else</span> {
            request.send(null);
        }

    } catch (errv) {
        document.getElementById(<span class="literal">'error'</span>).innerHTML =
        <span class="literal">"No es pot contactar amb el servidor en aquest moment.\n "</span>+
        <span class="literal">"Si us plau torneu a provar-ho en uns segons.\n"</span>+
        <span class="literal">"Detall de l'error : "</span>+errv.message;
    }
}

<span class="comment">/**
 * Aquesta funcio crea una peticio adaptada al tipus de navagador que s'utilitza
 * Si la peticio es POST envia a executar els par`ametres adequats.
 * Parametres :
 *  [0] - reqType    : es el tipus de peticio (GET o POST)
 *  [1] - url        : es l'adreca complerta de la peticio
 *  [2] - asynch     : es si es sincrona false, o asincrona true
 *  [3] - respHandle : es la funcio destinataria de la resposta.
 *  [4] - (opcional) : Aquest parametre pot rebre per exemple  una llista de peticio
 *                     o qualsevol altre cosa que es vulgui enviar amb POST
 *  Emet un missatge d'error si no es pot crear la peticio
 */</span>
<span class="reserved">function</span> httpRequest(reqType,url,asynch,respHandle){
    <span class="reserved">if</span>(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    } <span class="reserved">else</span> <span class="reserved">if</span> (window.ActiveXObject){
        request=new ActiveXObject(<span class="literal">"Msxml2.XMLHTTP"</span>);
        <span class="reserved">if</span> (! request){
            request=new ActiveXObject(<span class="literal">"Microsoft.XMLHTTP"</span>);
        }
    }
    <span class="reserved">if</span>(request)  {
        <span class="reserved">if</span>(reqType.toLowerCase() != <span class="literal">"post"</span>) {
            initReq(reqType,url,asynch,respHandle);
        }  <span class="reserved">else</span> {
            var args = arguments[4];
            <span class="reserved">if</span>(args != null &amp;&amp; args.length &gt; 0){
                initReq(reqType,url,asynch,respHandle,args);
            }
        }
    }  <span class="reserved">else</span> {
          document.getElementById(<span class="literal">'error'</span>).innerHTML = <span class="literal">"El vostre navegador, no permet l'ús de totes "</span>+
    <span class="literal">"les característiques d'aquesta aplicació!"</span>;
    }
}

<span class="comment">/**
 * Donat un formulari, extreu a la variable queryString tots els camps del formulari
 * amb els seus valors, formatat per fer una peticio.
 * <span class="attrib">@param</span> x
 */</span>
<span class="reserved">function</span> setQueryString(x){
queryString=<span class="literal">""</span>;
    var frm = document.forms[x];
    var numberElements =  frm.elements.length;
    <span class="reserved">for</span>(var i = 0; i &lt; numberElements; i++)  {
        <span class="reserved">if</span>(i &lt; numberElements-1)  {
            queryString += frm.elements[i].name+<span class="literal">"="</span>+encodeURIComponent(frm.elements[i].value)+<span class="literal">"&amp;"</span>;
                } <span class="reserved">else</span> {
        queryString += frm.elements[i].name+<span class="literal">"="</span>+encodeURIComponent(frm.elements[i].value);
            }
        }
        }

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Fri May 29 19:40:22 2009</div>
</body>
</html>
